package com.yin.myproject.thread.syncdemo;

/**
 * @author Eason
 * @create 2018-05-09 15:47
 **/
public class Counter {
    private static int count = 0;

    public int getCount() {
        return count;
    }

    public synchronized static void increase() {
//        synchronized (this) {
        try {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + ":" + (count++));
                Thread.sleep(100);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        }
    }

    public synchronized void decrease() {
//        synchronized (this) {
        try {
            for (int i = 0; i < 5; i++) {
                System.out.println(Thread.currentThread().getName() + ":" + (count--));
                Thread.sleep(100);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        }
    }
}
